<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>实时监测加载的进度条</title>
    <style>
      .loading {
        width: 100%;
        height: 100%;
        position: fixed;
        top: 0;
        left: 0;
        z-index: 1000;
        background: #fff;
      }
      .loading .pic {
        height: 100px;
        width: 100px;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        margin: auto;
        font-size: 20px;
        line-height: 100px;
        text-align: center;
      }
      .loading .pic span {
        display: block;
        height: 80px;
        width: 80px;
        position: absolute;
        top: 10px;
        left: 10px;
        border-radius: 50%;
        -webkit-box-shadow: 0 3px 0 #666;
        box-shadow: 0 3px 0 #666;
        -webkit-animation: rotate 1s infinite linear;
        animation: rotate 1s infinite linear;
      }
      @-webkit-keyframes rotate {
        0% {
          -webkit-transform: rotate(0deg);
          transform: rotate(0deg);
        }
        100% {
          -webkit-transform: rotate(360deg);
          transform: rotate(360deg);
        }
      }
      @keyframes rotate {
        0% {
          -webkit-transform: rotate(0deg);
          transform: rotate(0deg);
        }
        100% {
          -webkit-transform: rotate(360deg);
          transform: rotate(360deg);
        }
      }
      img {
        margin-bottom: 30px;
        margin-left: 5vw;
        height: 90vh;
        width: 90vw;
        display: block;
        border: 3px solid #000;
      }
    </style>
    <script type="text/javascript" src="js/jquery.js"></script>
    <script>
      $(function() {
        //获得img元素
        var img = $("img");
        var num = 0;
        //遍历img
        img.each(function(i) {
          //创建img对象
          var oImg = new Image();
          //监测img对象的加载过程
          oImg.onload = function() {
            oImg.onload = null;
            num++;
            $(".loading b").html(parseInt(num / $("img").size() * 100) + "%");
            if(num >= i) {
              $(".loading").fadeOut();
            }
          }
          //设置img对象的图片地址
          oImg.src = img[i].src;
        })
      })
    </script>
  </head>
  <body>
    <div class="loading">
      <div class="pic">
        <span></span>
        <b>0%</b>
      </div>
    </div>
    <div class="box">
      <img src="https://github.com/CruxF/IMOOC/blob/master/ProImages/ImgPreloading01.jpg?raw=true" />
      <img src="https://github.com/CruxF/IMOOC/blob/master/ProImages/ImgPreloading02.jpg?raw=true" />
      <img src="https://github.com/CruxF/IMOOC/blob/master/ProImages/ImgPreloading03.jpg?raw=true" />
      <img src="https://github.com/CruxF/IMOOC/blob/master/ProImages/ImgPreloading04.jpg?raw=true" />
      <img src="https://github.com/CruxF/IMOOC/blob/master/ProImages/ImgPreloading05.jpg?raw=true" />
      <img src="https://github.com/CruxF/IMOOC/blob/master/ProImages/ImgPreloading06.jpg?raw=true" />
      <img src="https://github.com/CruxF/IMOOC/blob/master/ProImages/ImgPreloading07.jpg?raw=true" />
      <img src="https://github.com/CruxF/IMOOC/blob/master/ProImages/ImgPreloading08.jpg?raw=true" />
      <img src="https://github.com/CruxF/IMOOC/blob/master/ProImages/ImgPreloading09.jpg?raw=true" />
      <img src="https://github.com/CruxF/IMOOC/blob/master/ProImages/ImgPreloading10.jpg?raw=true" />
    </div>
  </body>
</html>